<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/css/bootstrap3/bootstrap-switch.min.css"
      rel="stylesheet">
<!-- 新 Bootstrap4 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="../css/bootstrap-table.min.css">
<!-- 新 Bootstrap4 核心 CSS 文件 -->
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/js/bootstrap-switch.min.js"></script>
<!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单，包含了 popper.min.js -->
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="../js/bootstrap-table.min.js"></script>
<script src="../js/bootstrap-table-zh-CN.min.js"></script>
<body>
<div class="container">

    <div class="modal fade m-auto" id="myModal">
        <div class="modal-dialog modal-xl" style="width: 1000px;height: 800px">
            <div class="modal-content">

                <!--     制作设计单模态框       -->
                <!-- 模态框头部 -->
                <div class="modal-header">
                    <h4 class="modal-title">生产工序设计单</h4>
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                </div>

                <!-- 模态框主体 -->
                <div class="modal-body">
                    <div class="m-auto row">
                        <!-- 父级编号 -->
                        <span id="parentId" style="display: none"></span>

                        <div class="col"><span>设计单编号:</span><span id="id"></span></div>
                        <div class="col"><span>设计人:</span><span id="designer"></span></div>
                    </div>
                    <div class="m-auto row" style="padding-top: 15px">
                        <div class="col"><span>产品名称:</span><span id="name"></span></div>
                        <div class="col"><span>产品编号:</span><span id="productId"></span></div>

                    </div>
                    <div style="padding-top: 15px">
                        <table id="tab1" class="table table-striped table-bordered table-hover">
                            <thead style="background-color: #aeaeae;border: 1px solid black">
                            <tr>
                                <th>点选</th>
                                <th>工序名称</th>
                                <th>工序编号</th>
                                <th>描述</th>
                                <th>工时数</th>
                                <th>工时单位</th>
                                <th>单位工时成本</th>
                                <th>工时成本小计(元)</th>
                            </tr>
                            </thead>
                            <tbody id="product">
                            <tr>
                                <td><input class="checkd" id="assemble" type="checkbox" style="width: 30px;"></td>
                                <td class="procedureName">组装</td>
                                <td class="procedureId">001</td>
                                <td class="procedureDescribe"><input type="text" style="width: 90px;"></td>
                                <td class="labourHourAmount"><input class="calculate" id="zgss" type="number"
                                                                    style="width: 90px;"></td>
                                <td class="amountUnit"><input type="text" style="width: 90px;"></td>
                                <td class="costPrice"><input class="calculate" id="zcb" type="number"
                                                             style="width: 90px;">
                                </td>
                                <td class="subtotal"><span id="zSum">0</span></td>
                            </tr>
                            <tr>
                                <td><input class="checkd" id="test" type="checkbox" style="width: 30px;"></td>
                                <td class="procedureName">测试</td>
                                <td class="procedureId">002</td>
                                <td class="procedureDescribe"><input type="text" style="width: 90px;"></td>
                                <td class="labourHourAmount"><input class="calculate" id="cgss" type="number"
                                                                    style="width: 90px;"></td>
                                <td class="amountUnit"><input type="text" style="width: 90px;"></td>
                                <td class="costPrice"><input class="calculate" id="ccb" type="number"
                                                             style="width: 90px;">
                                </td>
                                <td class="subtotal"><span id="cSum">0</span></td>
                            </tr>
                            <tr>
                                <td><input class="checkd" id="packaging" type="checkbox" style="width: 30px;"></td>
                                <td class="procedureName">包装</td>
                                <td class="procedureId">003</td>
                                <td class="procedureDescribe"><input type="text" style="width: 90px;"></td>
                                <td class="labourHourAmount"><input class="calculate" id="bgss" type="number"
                                                                    style="width: 90px;"></td>
                                <td class="amountUnit"><input type="text" style="width: 90px;"></td>
                                <td class="costPrice"><input class="calculate" id="bcb" type="number"
                                                             style="width: 90px;">
                                </td>
                                <td class="subtotal"><span id="bSum">0</span></td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <div><span>工时成本:</span><span id="costPriceSum"></span></div>
                    <div class="m-auto row" style="padding-top: 15px">
                        <div class="col"><span>审核人:</span><span id="person"></span></div>
                        <div class="col"><span>审核时间:</span><span id="checkTime"></span></div>
                    </div>
                    <div class="row m-auto" style="padding-top: 15px">
                        <span class="col-3">设计要求:</span><textarea id="procedureDescribe"
                                                                  style="width: 500px; height: 100px;"></textarea>
                    </div>
                </div>

                <!-- 模态框底部 -->
                <div class="modal-footer">
                    <button type="button" class="btn btn-success" style="width: 90px;"
                            onclick="MDesignProcedureObj.MDesignProcedurePass()">通过
                    </button>
                    <button type="button" class="btn btn-warning" style="width: 90px;"
                            onclick="MDesignProcedureObj.MDesignProcedureNoPass()">不通过
                    </button>
                </div>


            </div>
        </div>
    </div>

</div>
<nav class="breadcrumb">
    <a class="breadcrumb-item" href="#">生产管理</a>
    <a class="breadcrumb-item" href="#">产品生产工序设计</a>
    <a class="breadcrumb-item" active href="#">产品生产工序设计单审核</a>
</nav>

<div class="input-group mb-3" style="width: 50%">
    <div class="input-group-prepend">
        <span class="input-group-text">设计编号</span>
    </div>

    <input id="designId" type="text" class="form-control">
    &nbsp;
    <div class="input-group-prepend">
        <span class="input-group-text">产品名称</span>
    </div>

    <input id="productName" type="text" class="form-control">
    &nbsp;
    <button onclick="$('#tab').bootstrapTable('refresh')" class="btn btn-primary">查询</button>
</div>

<table id="tab">

</table>
</body>


<script>
    $(function () {

        $("#tab").bootstrapTable({
            method: "post",
            url: "/queryMDesignProcedureAll.action",
            striped: true,
            pageNumber: 1,
            pagination: true,
            sidePagination: "server",
            pageSize: 3,
            pageList: [3, 6, 9],
            queryParams: function (i) {
                return {
                    //计算当前页
                    // currentPage:(parts.offset/parts.limit)+1,
                    pageNumber: i.offset,
                    //每条页数
                    pageSize: i.limit,
                    designId: $("#designId").val(),
                    productName: $("#productName").val()
                }
            },
            columns: [
                {title: "设计单编号", field: "designId"},
                {title: "产品编号", field: "productId"},
                {title: "产品名称", field: "productName"},
                {title: "设计人", field: "designer"},
                {title: "登记时间", field: "registerTime"},
                {title: "工时总成本", field: "costPriceSum"},
                {
                    title: "审核", field: "id", align: "center",
                    formatter: function (value, row, index) {
                        return "<button onclick='MDesignProcedureObj.MDesignProcedureText(" + JSON.stringify(row) + ")' class=\"btn btn-primary\" data-toggle=\"modal\" data-target=\"#myModal\">审核</button>"
                    },
                }
            ]
        })
    })
</script>

<script>
    var MDesignProcedureObj = {
        MDesignProcedureText: function (MDesignProcedure) {
            $("#id").text(MDesignProcedure.designId)//设计单编号
            $("#designer").text(MDesignProcedure.designer)//设计人
            $("#name").text(MDesignProcedure.productName)//产品名称
            $("#productId").text(MDesignProcedure.productId)//产品编号
            $("#costPriceSum").text(MDesignProcedure.costPriceSum)//工时成本
            $("#checkTime").text(new Date().toLocaleString())//审核时间
            $("#procedureDescribe").val(MDesignProcedure.procedureDescribe)//设计要求

            //获取当前等人账号
            $.ajax({
                type: "post",
                url: "/user.action",
                success: function (i) {
                    $("#person").text(i.loginId)//审核人
                }
            })


            $("#tab1").bootstrapTable({
                method: "get",
                url: "/queryMDesignProcedureDetailsByParentId.action",
                striped: true,
                queryParams: function (params) {
                    return {
                        id: MDesignProcedure.id
                    }
                },
                columns: [
                    {title: "序号", field: "id"},
                    {title: "工序名称", field: "procedureName"},
                    {title: "工序编号", field: "procedureId"},
                    {title: "描述", field: "procedureDescribe",},
                    {title: "工时数", field: "labourHourAmount"},
                    {title: "单位", field: "amountUnit"},
                    {title: "单位工时成本", field: "costPrice"},
                    {title: "工时成本小计(元)", field: "subtotal"}
                ]
            })
        },

        //审核通过
        MDesignProcedurePass: function () {
            var mDesignProcedure = {
                checker: $("#person").text(),//审核人
                checkTime: $("#checkTime").text(),//审核时间
                designId: $("#id").text()

            }
            console.log(mDesignProcedure)

            $.ajax({
                type: "post",
                url: "/UpdateMDesignProcedureCheckTag.action",
                data: JSON.stringify(mDesignProcedure),
                contentType: "application/json;charset=utf-8",
                success: function (i) {
                    $('#tab').bootstrapTable('refresh')
                    $('#myModal').modal("hide");
                }
            })
        },
        //审核不通过
        MDesignProcedureNoPass: function () {
            var mDesignProcedure = {
                checker: $("#person").text(),//审核人
                checkTime: $("#checkTime").text(),//审核时间
                designId: $("#id").text()
            }
            console.log(mDesignProcedure)

            alert($("#productId").text())

            $.ajax({
                type:"post",
                url:"/UpdateNoDFileTag.action",
                data:"id="+$("#productId").text(),
                success:function (i){

                }
            })

            $.ajax({
                type: "post",
                url: "/UpdateMDesignProcedureNoPass.action",
                data: JSON.stringify(mDesignProcedure),
                contentType: "application/json;charset=utf-8",
                success: function (i) {
                    $('#tab').bootstrapTable('refresh')
                    $('#myModal').modal("hide");
                }
            })
        },

    }
</script>

</html>